import 'package:hi_common/util/color.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class HiBarrageSendWidget extends StatefulWidget {
  const HiBarrageSendWidget({super.key});

  @override
  State<StatefulWidget> createState() {
    return _HiBarrageSendWidgetState();
  }
}

class _HiBarrageSendWidgetState extends State<HiBarrageSendWidget> {
  final TextEditingController _controller = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: Column(
        children: [
          Expanded(
              child: GestureDetector(
            onTap: () {
              Navigator.pop(context);
            },
            child: Container(
              color: Colors.transparent,
            ),
          )),
          SafeArea(
              child: ColoredBox(
                  color: Colors.white,
                  child: Padding(
                      padding: const EdgeInsets.all(10),
                      child: Row(
                        children: [
                          Expanded(
                              child: Container(
                            decoration: BoxDecoration(
                                color: Colors.grey[200],
                                borderRadius: BorderRadius.circular(20)),
                            child: Padding(
                              padding:
                                  const EdgeInsets.only(left: 10, right: 10),
                              child: _buildInput(_controller, context),
                            ),
                          )),
                          const SizedBox(
                            width: 10,
                          ),
                          _buildSend()
                        ],
                      ))))
        ],
      ),
    );
  }

  _buildInput(TextEditingController editingController, BuildContext context) {
    return TextField(
      autofocus: true,
      style: const TextStyle(color: Colors.black,fontSize: 12),
      cursorColor: primary,
      onSubmitted: (value) {
        _send(value);
      },
      controller: editingController,
      decoration: const InputDecoration(
        isDense: true,
        hintText: '发个友善的弹幕见证下',
        border: InputBorder.none,
      ),
    );
  }

  _buildSend() {
    return InkWell(
      onTap: () {
        _send(_controller.text);
      },
      child: const Icon(
        Icons.send,
        color: Colors.grey,
      ),
    );
  }

  _send(String message) {
    Navigator.pop(context, message);
  }
}
